/**
 * Copyright (C) 2007 The AsyncMail Group <asyncmail@googlegroups.com>
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *         http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.googlecode.asyncmail.common;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.Properties;

public class DeliveryStatusRequest extends Properties {

    private static final long serialVersionUID = -34762837642674534L;
    
    public static final String DSN_RET = "X-DSN-Ret";
    public static final String ORIGINAL_ENVELOPE_ID = "Original-Envelope-Id";
    public static final String RECEIVED_FROM_MTA = "Received-From-MTA";
    public static final String ARRIVAL_DATE = "Arrival-Date";

    private ArrayList<PerRecipientStatusRequest> perRecipient;

    public void addPerRecipientStatusReqiest(PerRecipientStatusRequest status) {
        perRecipient.add(status);
    }

    public PerRecipientStatusRequest getPerRecipientStatusRequest(String recipient) {
        PerRecipientStatusRequest p;
        Iterator<PerRecipientStatusRequest> i = getPerRecipientStatusRequestIterator();
        while (i.hasNext()) {
            p = i.next();
            if (p.getProperty(PerRecipientStatusRequest.FINAL_RECIPIENT).equals("rfc822; "+recipient)) return p;
        }
        p = new PerRecipientStatusRequest();
        p.setProperty(PerRecipientStatusRequest.FINAL_RECIPIENT,"rfc822; "+recipient);
        perRecipient.add(p);
        return p;
    }

    public void removePerRecientStatusReqVoid(String recipient) {
        PerRecipientStatusRequest p;
        Iterator<PerRecipientStatusRequest> i = getPerRecipientStatusRequestIterator();
        while (i.hasNext()) {
            p = i.next();
            if (p.getProperty(PerRecipientStatusRequest.FINAL_RECIPIENT).equals("rfc822; "+recipient)) {
                i.remove();
                return;
            }
        }
    }

    public Iterator<PerRecipientStatusRequest> getPerRecipientStatusRequestIterator() {
        return perRecipient.iterator();
    }

    public DeliveryStatusRequest() {
        super();
        perRecipient = new ArrayList<PerRecipientStatusRequest>();
    }
}